﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;
using System.Drawing;
using fideeraSoft.Utils;
using fideeraSoft.Handlers;
using fideeraSoft.Entities;

namespace fideeraSoft.Paneles
{
    class ProveedorPanelAlta:PanelGeneral
    {
        private TextBox tbProveedorRazonSocial;
        private Label lbRazonSocial;
        private TextBox tbCuil;
        private Label lbCuil;
        private GroupBox gbAltaProveedor;
        private Button submit;        

        private FlowLayoutPanel flowLayoutPanel1;
        private FlowLayoutPanel flpGral;
        private Label lbId;
        private Label lbIdProv;
        private Label lbDireccion;
        private TextBox tbDireccion;
        private Label lbLocalidad;
        private TextBox tbLocalidad;
        private TextBox tbProvincia;
        private Label lbProvincia;
        private Label lbResponsable;
        private TextBox tbResponsable;
        private TableLayoutPanel tlpForm;
        private TextBox tbTelefono;
        private TextBox tbCelular;
        private Label lbTelefono;
        private Label lbCelular;        
        private TableLayoutPanel tlpBotones;
        private Button btVolver;
        
        private int locationPointTableBotones;


        public ProveedorPanelAlta()
        { }
        
        #region Constructor 
        public ProveedorPanelAlta(Handler handler)
        {
            try
            {
                this.formatearPanelGeneral(handler);                

                InitializeComponent();

                this.formatearTableTitulo("ALTA DE PROVEEDOR");
                formatearGroupBox();
                formatTableForm();
                formatearTablaLayoutBotones();
                              
                
                lbIdProv.Text = handler.buscarNuevoUltimoIdProveedorEnBD().ToString();                
                cargarControlsEnTabla();            
                gbAltaProveedor.Controls.Add(tlpForm);

                tlpBotones.Controls.Add(btVolver);
                tlpBotones.Controls.Add(submit);
                
                //submit.Location = new Point(MetodosGenerales.calcularCenterWidth(this.Size.Width, submit.Size.Width), initialPointVertical+gbAltaProveedor.Size.Height+50);

                this.Controls.Add(TlpTitulo);
               this.Controls.Add(gbAltaProveedor);
               this.Controls.Add(tlpBotones);
            }
            catch (MiException ex)
            {
                CLogger.Append("[FideeraForm] Exception: " + ex, CLogger.ERROR);      //DEBUG
            }

            //this.Controls.Add(gbAltaProveedor);            
        }
        #endregion

        
        private void formatearGroupBox()
        {
             
            gbAltaProveedor.Location = new Point(MetodosGenerales.calcularCenterWidth(this.handler.FormFrame.Size.Width, gbAltaProveedor.Size.Width), this.InitialRealPointVertical);
        }

        #region Formateo de la tabla del form
        private void formatTableForm()
        {
            //tlpForm.Size = new Size(gbAltaProveedor.Width-10,gbAltaProveedor.Height-300);

            tlpForm.ColumnStyles.Clear();
            for (int i = 0; i < tlpForm.ColumnCount; i++)
            {
                tlpForm.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            }

            tlpForm.RowStyles.Clear();
            for (int i = 0; i < tlpForm.RowCount; i++)
            {
                tlpForm.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            }

            //tlpForm.Size = new Size((gbAltaProveedor.Size.Width - 10));

            tlpForm.BackColor = Color.LightCyan;
            tlpForm.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
            tlpForm.Location = new Point(MetodosGenerales.calcularCenterWidth(gbAltaProveedor.Size.Width, tlpForm.Size.Width), 30);

        }
        #endregion

        private void formatearTablaLayoutBotones()
        {
                        
            locationPointTableBotones = this.InitialRealPointVertical + gbAltaProveedor.Size.Height + 30;

            tlpBotones.Location = new Point(MetodosGenerales.calcularCenterWidth(this.Size.Width, tlpBotones.Size.Width), locationPointTableBotones);
        }

        private void cargarControlsEnTabla()
        {
         //   this.tlpForm.RowCount = 10;

            tlpForm.Controls.Add(lbId);
            tlpForm.Controls.Add(lbIdProv);

            tlpForm.Controls.Add(lbRazonSocial);
            tlpForm.Controls.Add(tbProveedorRazonSocial);

            tlpForm.Controls.Add(lbCuil);
            tlpForm.Controls.Add(tbCuil);

            tlpForm.Controls.Add(lbResponsable);
            tlpForm.Controls.Add(tbResponsable);

            tlpForm.Controls.Add(lbDireccion);
            tlpForm.Controls.Add(tbDireccion);

            tlpForm.Controls.Add(lbLocalidad);
            tlpForm.Controls.Add(tbLocalidad);

            tlpForm.Controls.Add(lbProvincia);
            tlpForm.Controls.Add(tbProvincia);

            tlpForm.Controls.Add(lbTelefono);
            tlpForm.Controls.Add(tbTelefono);

            tlpForm.Controls.Add(lbCelular);
            tlpForm.Controls.Add(tbCelular);

            
        }


        private void InitializeComponent()
        {
            this.tbProveedorRazonSocial = new System.Windows.Forms.TextBox();
            this.submit = new System.Windows.Forms.Button();
            this.lbRazonSocial = new System.Windows.Forms.Label();
            this.tbCuil = new System.Windows.Forms.TextBox();
            this.lbCuil = new System.Windows.Forms.Label();
            this.gbAltaProveedor = new System.Windows.Forms.GroupBox();
            this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
            this.flpGral = new System.Windows.Forms.FlowLayoutPanel();
            this.tlpForm = new System.Windows.Forms.TableLayoutPanel();
            this.lbId = new System.Windows.Forms.Label();
            this.lbIdProv = new System.Windows.Forms.Label();
            this.lbDireccion = new System.Windows.Forms.Label();
            this.tbDireccion = new System.Windows.Forms.TextBox();
            this.lbLocalidad = new System.Windows.Forms.Label();
            this.tbLocalidad = new System.Windows.Forms.TextBox();
            this.tbProvincia = new System.Windows.Forms.TextBox();
            this.lbProvincia = new System.Windows.Forms.Label();
            this.lbResponsable = new System.Windows.Forms.Label();
            this.tbResponsable = new System.Windows.Forms.TextBox();
            this.tbTelefono = new System.Windows.Forms.TextBox();
            this.tbCelular = new System.Windows.Forms.TextBox();
            this.lbTelefono = new System.Windows.Forms.Label();
            this.lbCelular = new System.Windows.Forms.Label();
            this.tlpBotones = new System.Windows.Forms.TableLayoutPanel();
            this.btVolver = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // tbProveedorRazonSocial
            // 
            this.tbProveedorRazonSocial.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbProveedorRazonSocial.Location = new System.Drawing.Point(50, 100);
            this.tbProveedorRazonSocial.MaxLength = 60;
            this.tbProveedorRazonSocial.Name = "tbProveedorRazonSocial";
            this.tbProveedorRazonSocial.Size = new System.Drawing.Size(400, 29);
            this.tbProveedorRazonSocial.TabIndex = 0;
            // 
            // submit
            // 
            this.submit.BackColor = System.Drawing.Color.AliceBlue;
            this.submit.Font = new System.Drawing.Font("Bodoni MT", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.submit.ForeColor = System.Drawing.Color.Black;
            this.submit.Location = new System.Drawing.Point(200, 300);
            this.submit.Margin = new System.Windows.Forms.Padding(12, 3, 3, 3);
            this.submit.Name = "submit";
            this.submit.Size = new System.Drawing.Size(75, 40);
            this.submit.TabIndex = 0;
            this.submit.Text = "Guardar";
            this.submit.UseVisualStyleBackColor = false;
            this.submit.Click += new System.EventHandler(this.boton_Click);
            // 
            // lbRazonSocial
            // 
            this.lbRazonSocial.AutoSize = true;
            this.lbRazonSocial.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbRazonSocial.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbRazonSocial.Location = new System.Drawing.Point(200, 100);
            this.lbRazonSocial.Name = "lbRazonSocial";
            this.lbRazonSocial.Size = new System.Drawing.Size(100, 23);
            this.lbRazonSocial.TabIndex = 0;
            this.lbRazonSocial.Text = "Nombre o Razón Social";
            this.lbRazonSocial.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tbCuil
            // 
            this.tbCuil.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbCuil.Location = new System.Drawing.Point(50, 150);
            this.tbCuil.MaxLength = 11;
            this.tbCuil.Name = "tbCuil";
            this.tbCuil.Size = new System.Drawing.Size(135, 29);
            this.tbCuil.TabIndex = 0;
            // 
            // lbCuil
            // 
            this.lbCuil.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbCuil.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbCuil.Location = new System.Drawing.Point(350, 150);
            this.lbCuil.Name = "lbCuil";
            this.lbCuil.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.lbCuil.Size = new System.Drawing.Size(100, 23);
            this.lbCuil.TabIndex = 0;
            this.lbCuil.Text = "Cuit (sin -/)";
            this.lbCuil.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.lbCuil.UseWaitCursor = true;
            // 
            // gbAltaProveedor
            // 
            this.gbAltaProveedor.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.gbAltaProveedor.Font = new System.Drawing.Font("Bodoni MT", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.gbAltaProveedor.Location = new System.Drawing.Point(0, 0);
            this.gbAltaProveedor.Name = "gbAltaProveedor";
            this.gbAltaProveedor.Size = new System.Drawing.Size(800, 500);
            this.gbAltaProveedor.TabIndex = 0;
            this.gbAltaProveedor.TabStop = false;
            this.gbAltaProveedor.Text = "Alta de Proveedor";
            // 
            // flowLayoutPanel1
            // 
            this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.flowLayoutPanel1.Name = "flowLayoutPanel1";
            this.flowLayoutPanel1.Size = new System.Drawing.Size(450, 550);
            this.flowLayoutPanel1.TabIndex = 0;
            // 
            // flpGral
            // 
            this.flpGral.Location = new System.Drawing.Point(0, 0);
            this.flpGral.Name = "flpGral";
            this.flpGral.Size = new System.Drawing.Size(200, 100);
            this.flpGral.TabIndex = 0;
            // 
            // tlpForm
            // 
            this.tlpForm.ColumnCount = 2;
            this.tlpForm.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpForm.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpForm.Location = new System.Drawing.Point(0, 0);
            this.tlpForm.Name = "tlpForm";
            this.tlpForm.RowCount = 10;
            this.tlpForm.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpForm.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpForm.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
            this.tlpForm.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
            this.tlpForm.Size = new System.Drawing.Size(700, 400);
            this.tlpForm.TabIndex = 0;
            // 
            // lbId
            // 
            this.lbId.AutoSize = true;
            this.lbId.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbId.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbId.Location = new System.Drawing.Point(0, 0);
            this.lbId.Name = "lbId";
            this.lbId.Size = new System.Drawing.Size(100, 23);
            this.lbId.TabIndex = 0;
            this.lbId.Text = "ID del Proveedor";
            this.lbId.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lbIdProv
            // 
            this.lbIdProv.AutoSize = true;
            this.lbIdProv.Location = new System.Drawing.Point(0, 0);
            this.lbIdProv.Name = "lbIdProv";
            this.lbIdProv.Size = new System.Drawing.Size(100, 23);
            this.lbIdProv.TabIndex = 0;
            // 
            // lbDireccion
            // 
            this.lbDireccion.AutoSize = true;
            this.lbDireccion.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbDireccion.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbDireccion.Location = new System.Drawing.Point(0, 0);
            this.lbDireccion.Name = "lbDireccion";
            this.lbDireccion.Size = new System.Drawing.Size(100, 23);
            this.lbDireccion.TabIndex = 0;
            this.lbDireccion.Text = "Dirección";
            this.lbDireccion.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tbDireccion
            // 
            this.tbDireccion.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbDireccion.Location = new System.Drawing.Point(0, 0);
            this.tbDireccion.MaxLength = 60;
            this.tbDireccion.Name = "tbDireccion";
            this.tbDireccion.Size = new System.Drawing.Size(400, 30);
            this.tbDireccion.TabIndex = 0;
            // 
            // lbLocalidad
            // 
            this.lbLocalidad.AutoSize = true;
            this.lbLocalidad.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbLocalidad.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbLocalidad.Location = new System.Drawing.Point(0, 0);
            this.lbLocalidad.Name = "lbLocalidad";
            this.lbLocalidad.Size = new System.Drawing.Size(100, 23);
            this.lbLocalidad.TabIndex = 0;
            this.lbLocalidad.Text = "Localidad";
            this.lbLocalidad.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tbLocalidad
            // 
            this.tbLocalidad.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbLocalidad.Location = new System.Drawing.Point(0, 0);
            this.tbLocalidad.Name = "tbLocalidad";
            this.tbLocalidad.Size = new System.Drawing.Size(200, 30);
            this.tbLocalidad.TabIndex = 0;
            // 
            // tbProvincia
            // 
            this.tbProvincia.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbProvincia.Location = new System.Drawing.Point(0, 0);
            this.tbProvincia.MaxLength = 40;
            this.tbProvincia.Name = "tbProvincia";
            this.tbProvincia.Size = new System.Drawing.Size(200, 30);
            this.tbProvincia.TabIndex = 0;
            // 
            // lbProvincia
            // 
            this.lbProvincia.AutoSize = true;
            this.lbProvincia.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbProvincia.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbProvincia.Location = new System.Drawing.Point(0, 0);
            this.lbProvincia.Name = "lbProvincia";
            this.lbProvincia.Size = new System.Drawing.Size(100, 23);
            this.lbProvincia.TabIndex = 0;
            this.lbProvincia.Text = "Provincia";
            this.lbProvincia.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lbResponsable
            // 
            this.lbResponsable.AutoSize = true;
            this.lbResponsable.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbResponsable.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbResponsable.Location = new System.Drawing.Point(0, 0);
            this.lbResponsable.Name = "lbResponsable";
            this.lbResponsable.Size = new System.Drawing.Size(100, 23);
            this.lbResponsable.TabIndex = 0;
            this.lbResponsable.Text = "Responsable";
            this.lbResponsable.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tbResponsable
            // 
            this.tbResponsable.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbResponsable.Location = new System.Drawing.Point(0, 0);
            this.tbResponsable.MaxLength = 50;
            this.tbResponsable.Name = "tbResponsable";
            this.tbResponsable.Size = new System.Drawing.Size(250, 30);
            this.tbResponsable.TabIndex = 0;
            // 
            // tbTelefono
            // 
            this.tbTelefono.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbTelefono.ImeMode = System.Windows.Forms.ImeMode.On;
            this.tbTelefono.Location = new System.Drawing.Point(0, 0);
            this.tbTelefono.MaxLength = 15;
            this.tbTelefono.Name = "tbTelefono";
            this.tbTelefono.Size = new System.Drawing.Size(160, 29);
            this.tbTelefono.TabIndex = 0;
            // 
            // tbCelular
            // 
            this.tbCelular.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbCelular.Location = new System.Drawing.Point(0, 0);
            this.tbCelular.MaxLength = 15;
            this.tbCelular.Name = "tbCelular";
            this.tbCelular.Size = new System.Drawing.Size(160, 29);
            this.tbCelular.TabIndex = 0;
            // 
            // lbTelefono
            // 
            this.lbTelefono.AutoSize = true;
            this.lbTelefono.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbTelefono.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbTelefono.Location = new System.Drawing.Point(0, 0);
            this.lbTelefono.Name = "lbTelefono";
            this.lbTelefono.Size = new System.Drawing.Size(100, 23);
            this.lbTelefono.TabIndex = 0;
            this.lbTelefono.Text = "Teléfono";
            this.lbTelefono.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lbCelular
            // 
            this.lbCelular.AutoSize = true;
            this.lbCelular.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbCelular.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbCelular.Location = new System.Drawing.Point(0, 0);
            this.lbCelular.Name = "lbCelular";
            this.lbCelular.Size = new System.Drawing.Size(100, 23);
            this.lbCelular.TabIndex = 0;
            this.lbCelular.Text = "Celular";
            this.lbCelular.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tlpBotones
            // 
            this.tlpBotones.BackColor = System.Drawing.Color.LightCyan;
            this.tlpBotones.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            this.tlpBotones.ColumnCount = 2;
            this.tlpBotones.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpBotones.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpBotones.Location = new System.Drawing.Point(0, 0);
            this.tlpBotones.Name = "tlpBotones";
            this.tlpBotones.RowCount = 1;
            this.tlpBotones.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpBotones.Size = new System.Drawing.Size(200, 46);
            this.tlpBotones.TabIndex = 0;
            // 
            // btVolver
            // 
            this.btVolver.BackColor = System.Drawing.Color.AliceBlue;
            this.btVolver.Font = new System.Drawing.Font("Bodoni MT", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btVolver.Location = new System.Drawing.Point(0, 0);
            this.btVolver.Margin = new System.Windows.Forms.Padding(12, 3, 3, 3);
            this.btVolver.Name = "btVolver";
            this.btVolver.Size = new System.Drawing.Size(75, 40);
            this.btVolver.TabIndex = 0;
            this.btVolver.Text = "Volver";
            this.btVolver.UseVisualStyleBackColor = false;
            this.btVolver.Click += new System.EventHandler(this.btVolver_Click);
            // 
            // ProveedorPanelAlta
            // 
            this.AutoSize = true;
            this.ResumeLayout(false);

        }

        private void boton_Click(object sender, EventArgs e)
        {

            if (validarTextBoxProveedor())
            {
                if (tbCuil.Text.Length == 11)
                {
                    Proveedor prov = new Proveedor();

                    try
                    {
                        cargarTextBoxEnProveedor(prov);
                    }
                    catch (MiException ex)
                    {
                        //  CLogger.Append("[btSubmit_Click] Exception: " + ex, CLogger.ERROR);      //DEBUG
                        MessageBox.Show("Error al dar de alta Usuario - Datos Incompletos", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    
                    try
                    {

                        

                        if (handler.buscarProveedorPorCuil(prov.Cuil) != null)
                        {
                            MessageBox.Show("Ya existe un proveedor con ese numero de cuil", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            handler.altaProveedor(prov);
                            //CLogger.Append("[boton_Click]ALTA - DATOS PROVEEDOR: " + prov.toString(), CLogger.INFO);      //DEBUG

                            MessageBox.Show("Nuevo proveedor creado correctamente", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            limpiarTextBoxs();
                            lbIdProv.Text = handler.buscarNuevoUltimoIdProveedorEnBD().ToString();
                        }
                    }catch(MiException ex)
                    {
                       // CLogger.Append("[boton_Click] Exception: "+ex, CLogger.ERROR);      //DEBUG
                        MessageBox.Show("Error al dar de alta Proveedor", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }


                }
                else 
                {
                    MessageBox.Show("CANTIDAD DE DIGITOS CUIL INCORRECTO","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                }

            }
            else
            {
                MessageBox.Show("INGRESO DE DATOS INCORRECTO", "ERROR",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
            }


        }

        private bool validarTextBoxProveedor()
        {
            return !(string.IsNullOrWhiteSpace(tbCuil.Text)) && !(string.IsNullOrWhiteSpace(tbDireccion.Text)) && !(string.IsNullOrWhiteSpace(tbProveedorRazonSocial.Text));
        }

        private void limpiarTextBoxs()
        {
            tbCelular.Clear();
            tbCuil.Clear();
            tbDireccion.Clear();
            tbLocalidad.Clear();
            tbProveedorRazonSocial.Clear();
            tbProvincia.Clear();
            tbResponsable.Clear();
            tbTelefono.Clear();

        }

        private void cargarTextBoxEnProveedor(Proveedor prov)
        {
            if (!string.IsNullOrWhiteSpace(lbId.Text)) prov.IdProveedor = Convert.ToInt32(lbIdProv.Text.ToString()); else throw new MiException("Error en id proveedor");

            if (!string.IsNullOrWhiteSpace(tbCuil.Text)) prov.Cuil = tbCuil.Text.ToString(); else throw new MiException("Error en cuil proveedor");
            if (!string.IsNullOrWhiteSpace(tbProveedorRazonSocial.Text)) prov.RazonSocial = tbProveedorRazonSocial.Text; else throw new MiException("Error en razon social proveedor");
            
            if (!string.IsNullOrWhiteSpace(tbResponsable.Text)) prov.Responsable = tbResponsable.Text; else prov.Responsable = "";
            if (!string.IsNullOrWhiteSpace(tbDireccion.Text)) prov.Direccion = tbDireccion.Text; else prov.Direccion = "";
            if (!string.IsNullOrWhiteSpace(tbLocalidad.Text)) prov.Localidad = tbLocalidad.Text; else prov.Localidad = "";
            if (!string.IsNullOrWhiteSpace(tbProvincia.Text)) prov.Provincia = tbProvincia.Text; else prov.Provincia = "";
            if (!string.IsNullOrWhiteSpace(tbTelefono.Text)) prov.Telefono = tbTelefono.Text.ToString(); else prov.Telefono = "";
            if (!string.IsNullOrWhiteSpace(tbCelular.Text)) prov.Celular = tbCelular.Text.ToString(); else prov.Celular = "";
            

        }

        private void btVolver_Click(object sender, EventArgs e)
        {
            handler.backToPrincipal();
        }


    }
}
